package castledefense.gui.upgradePanel;

import twl.global.widget.LabelFonts;
import castledefense.logic.Map;
import castledefense.logic.buildings.Castle;
import de.matthiasmann.twl.Widget;
import de.matthiasmann.twl.renderer.AnimationState.StateKey;

public class CastleInfoPanel extends Widget{
	public static final StateKey STATE_TOWER1 = StateKey.get("tower1");
	public static final StateKey STATE_TOWER2 = StateKey.get("tower2");
	public static final StateKey STATE_GATE = StateKey.get("gate");
	public static final StateKey STATE_CASTLE = StateKey.get("castle");
	
	public static final StateKey STATE_FIRE = StateKey.get("fire");
	public static final StateKey STATE_WATER = StateKey.get("water");
	public static final StateKey STATE_EARTH = StateKey.get("earth");
	public static final StateKey STATE_AIR = StateKey.get("air");
	
	private Widget buildingImage;
	private Widget effectImage;
	private LabelFonts labelTitle;
	private LabelFonts labelLevel;
	private LabelFonts labelDescription;
	private LabelFonts labelHealth;
	private LabelFonts labelRegeneration;
	
	public CastleInfoPanel() {
		//BuildingButtonPanel
		int width = (int) (Map.cellWidth * 1.5);
		int height = (int) (Map.cellWidth * 1.5);
		width = 45;
		height = 45;

		setTheme("");
		
		buildingImage = new Widget();
		buildingImage.setTheme("buildingIconTheme");
		buildingImage.setSize(width, height);
		buildingImage.setPosition(10, 10);
		add(buildingImage);

		labelTitle = new LabelFonts();
		labelTitle.setTheme("labelTheme");
		labelTitle.setFont("arialBold20");
		labelTitle.setPosition(62, 20);
		add(labelTitle);

		labelLevel = new LabelFonts();
		labelLevel.setTheme("labelTheme");
		labelLevel.setFont("arialBoldItalic16");
		labelLevel.setColor(LabelFonts.STATE_BLACK);
		labelLevel.setPosition(62, 42);
		add(labelLevel);
		
		Widget line = new Widget();
		line.setTheme("fillRectBlack");
		line.setSize(159, 1);
		line.setPosition(10, 60);
		add(line);
		
		labelDescription = new LabelFonts();
		labelDescription.setTheme("labelTheme");
		labelDescription.setFont("arialItalic16");
		labelDescription.setPosition(10, 80);
		add(labelDescription);
		
		
		
		LabelFonts health = new LabelFonts("Health");
		health.setTheme("labelTheme");
		health.setFont("arialBold16");
		health.setPosition(10, 110);
		add(health);
		
		LabelFonts regeneration = new LabelFonts("Repair");
		regeneration.setTheme("labelTheme");
		regeneration.setFont("arialBold16");
		regeneration.setPosition(10, 125);
		add(regeneration);
		
		labelHealth = new LabelFonts();
		labelHealth.setTheme("labelTheme");
		labelHealth.setFont("arialBold15");
		labelHealth.setPosition(70, 110);
		add(labelHealth);
		
		labelRegeneration = new LabelFonts();
		labelRegeneration.setTheme("labelTheme");
		labelRegeneration.setFont("arialBold15");
		labelRegeneration.setPosition(70, 125);
		add(labelRegeneration);
		
		effectImage = new Widget();
		effectImage.setTheme("elementIconTheme");
		effectImage.setPosition(80, 162);
		effectImage.setSize(16, 16);
		add(effectImage);
		
	}
	
	public void draw(Castle castle, Widget rootPane) {

		labelTitle.setText("Castle");
		//labelHotkey.setText("(Hotkey = " + button.getHotkey() + ")");
		labelDescription.setText("The building you must\nprotect.");
		labelHealth.setText(":  " + (int)castle.getLife() + " / " + (int)castle.getInitialLife());
		labelRegeneration.setText(":  1 / " + (int)(1/castle.getRegeneration()) + " s");

		buildingImage.getAnimationState().setAnimationState(STATE_CASTLE, true);
		
		if(!(rootPane.getNumChildren() == 1 && rootPane.getChild(0) == this)){
			rootPane.removeAllChildren();
			rootPane.add(this);
		}
	}

}
